<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>创建一个节点</title>
		<script type="text/javascript" src="../FWK/Package.js"></script>
		<script type="text/javascript">
			FWK.include([
				"FWK.Util.createElement"
			]);
		</script>
	</head>
	<body>
		<div id="$_setSay">
		  	话语设定 <input type="text" name="$_sayCot" id="$_say_cot" maxLength="24"/>
		 </div>
		
		<div id="$_content_say"></div>
		
		<div id="$_setBtn">
		  	<input type="button" onclick="addSayCot()" value="添加对话"/>
		  	<input type="button" onclick="removeSayCot()" style="display:none;" value="移除对话" id="$_div_removeSay"/>
		</div>
		
		<div id="tishi_maxCount"></div>
		
		
		<input type="button" value="确定" onclick="sure()" />
		
		<script type="text/javascript">
			/**
			 * 去掉字符串两端空格
			 */
			String.prototype.trim = function() {
				return this.replace(/(\s*$)/g,"");
			}
			
			addSayCot.count = 1;
			
			function addSayCot() {
				var _div = $("$_content_say");
				var _removeDom = $("$_div_removeSay");
				
				if (addSayCot.count > 5) {
					$("tishi_maxCount").innerHTML = "已经到达场景最大对话数";
					return;
				}
				
				addSayCot.count++;
				
				if(addSayCot.count > 1 && _removeDom.style.display == "none") {
					_removeDom.style.display = "";
				}

				var dom = FWK.Util.createElement("div",{},[
					["label",{innerHTML:"间隔"}],
					["input",{type:"text",name:"$_sayTime_ipt",style:{width:"20px"}}],
					["label",{innerHTML:"秒"}],
					["input",{type:"text",name:"$_sayCot_ipt"}]
				],_div);
			}
		
			function removeSayCot() {
				var tishiDom = $("tishi_maxCount");

				if(addSayCot.count<= 1) {
					return;
				} else {
					if(tishiDom.innerHTML == "已经到达场景最大对话数")  tishiDom.innerHTML = "";
				}
				
				addSayCot.count--;
				
				if(addSayCot.count <=1) {
					$("$_div_removeSay").style.display = "none";
				} 
				
				var parent = $("$_content_say");
				
				var childs = parent.getElementsByTagName("div");
				
				var len = childs.length;
				
				parent.removeChild(childs[len-1]);
			}
			
			function sure() {
				var reg = /^[1-9]+$/;
				
				var times = document.getElementsByName("$_sayTime_ipt");
				var cots = document.getElementsByName("$_sayCot_ipt");
				
				for(var i=0,j=times.length;i<j;i++) {
					var flag = times[i].value;
					
					if(!reg.test(flag)) {
						alert("请输入正确的时间间隔，时间间隔为大于0的正整数");
						times[i].focus();
						return false;
					}
					
					if(cots[i].value.trim() == "") {
						alert("话语内容不能为空");
						cots[i].focus();
						return false;
					}
				}		
			}
		</script>
	</body>
</html>
